package assignment3;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeMap;

public class average {

	public static void main(String[] args) {
		try {
			File file = new File(
					"/Documents and Settings/Dave/Desktop/re2.dat");
			Scanner sc = new Scanner(file);

			ArrayList<String> lst = new ArrayList<String>();
			ArrayList<String> lst2 = new ArrayList<String>();
			ArrayList<Object> lst3 = new ArrayList<Object>();
			
			while (sc.hasNextLine()) {
				String line = sc.nextLine();
				lst.add(line);
			}
			double x = 0;
			int b = 0;

			for (int i = 0; i < lst.size(); ++i) {
				Scanner sc1 = new Scanner(lst.get(i));
				while (sc1.hasNext()) {
					if (sc1.next() == " ") {
						x += 0;
					} else {
						x += 1;
						b += 1;
					}

				}
			}
			int z = 0;

			for (int c = 0; c < lst.size(); ++c) {
				Scanner sc2 = new Scanner(lst.get(c));
				while (sc2.hasNext()) {
					String q = sc2.next();
					if (lst2.contains(q)) {
						z += 0;
						lst2.add(q);
					} else {
						z += 1;
						lst2.add(q);
					}
				}
			}
			int e = 0;
			TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
			for (int d = 0; d < lst.size(); ++d) {
				e = 0;
				Scanner sc3 = new Scanner(lst.get(d));
				while (sc3.hasNext()) {
					String r = sc3.next();
					if (r == " ") {
						e += 0;
					} else {
						e += 1;
					}
				}
				if (map.get(e) == null) {
					map.put(e, 1);
				} else {
					map.put(e, (map.get(e) + 1));
				}
			}
			int l = 0;
			for (int s = 0; s < lst.size(); ++s) {
				Scanner sc4 = new Scanner(lst.get(s));
				HashMap<String, Integer> hmap = new HashMap<String, Integer>();
				while (sc4.hasNext()) {
					String r = sc4.next();
					if (r == " ") {
						l += 0;
					} else {
						if (hmap.get(r) != null) {
							hmap.put(r, (hmap.get(r) + 1));
							
						} else {
							hmap.put(r, 1);
						}
						if (hmap.get(r) > 1) {
							lst3.add(r);
						}
					}
				}
			}
			

			System.out.printf("There are %s baskets\n", lst.size());
			System.out.printf("%s items\n", b);
			System.out.printf("%s unique items\n", z);
			System.out.printf("first: \"%s\"\n", lst.get(0));
			System.out.printf("last: \"%s\"\n", lst.get(lst.size() - 1));
			System.out.printf("average: \"%s\"\n", (x / (lst.size())));
			System.out.printf("keySet: \"%s\"\n", (map.keySet()));
			System.out.printf("map values: \"%s\"\n", (map.values()));
			System.out.printf("lst3: \"%s\"\n", (lst3));

			// print the entire contents of the file
			// for (int i = 0; i < lst.size(); ++i) {
			// System.out.println(lst.get(i));
			// }

		} catch (IOException e) {
			System.out.println("I/O error: " + e);
		}
	}
}
